package com.sinosoft.brokerchannel.rest;

import com.sinosoft.brokerchannel.base.annotation.MyResponseBody;
import com.sinosoft.brokerchannel.base.common.SystemParamFinal;
import com.sinosoft.brokerchannel.base.rest.AbstractController;
import com.sinosoft.brokerchannel.base.server.LogService;
import com.sinosoft.brokerchannel.base.utile.BusinessException;
import com.sinosoft.brokerchannel.entity.vo.IusEchoQueryRequest;
import com.sinosoft.brokerchannel.entity.vo.IusEchoQueryResponse;
import com.sinosoft.brokerchannel.entity.vo.IusLoginQueryRequest;
import com.sinosoft.brokerchannel.entity.vo.IusLoginQueryResponse;
import com.sinosoft.brokerchannel.server.impl.IusServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 需求名称：[保险经纪渠道平台]<br/>
 *
 * @author gzj
 * @version V1.0
 * @date 2018-8-21 10:48
 * 销售模块回显
 */
@Api(value = "services", description = "车险渠道平台销售模块回显")
@Controller
@RequestMapping("/salesReturn")
public class IusEchoQueryController extends AbstractController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private LogService logService;
    @Autowired
    private IusServiceImpl iusService;
    @RequestMapping(value = "/selectEcho", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "回显", notes = "回显")
    @MyResponseBody
    public IusEchoQueryResponse selectLogin(@RequestBody IusEchoQueryRequest request) throws Exception {
        IusEchoQueryResponse response = new IusEchoQueryResponse();
        ;//响应对象
        String flowid = "";//交易ID
        try {
            //初始化
            super.init("Ius列表查询", request.getRequestHead());
            //记录日志
            flowid = super.beforeTheTransaction(request);
            //调用服务
            response = iusService.selectEcho(request);
            //status的状态：1：成功；0：失败；2：暂无数据
            if ("1".equals(response.getResponseBody().getStatus())) {
                super.sucessAction();
            } else {
                super.errorAction(response.getResponseBody().getMsg());
            }
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            super.exceptionAction(e);
            logger.info(SystemParamFinal.Exception_LOG, e);
        } finally {
            if (response == null) {
                response = new IusEchoQueryResponse();
            }
            response.setResponseHead(super.getResponseHead());
            //回写日志
            super.afterTheTransaction(response, flowid);
        }
        return response;
    }
}
